<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 16. 数组去重 [1,1,1,2,2,3,4,5,6,3,4,2,4,1,] ---> [1,2,3,4,5,6]

    function deWeight (arr) {
      // 记录开始与结束的下标
      var start = 0
      var end = 1
      for (var i = 0; i < arr.length - 1; i++) {
        // 判定为是重复的则end++
        if (arr[start] === arr[end]) {
          end++
        } else {
          // 有重复字段的话就裁剪
          if (end - start > 1) {
            arr.splice(start + 1, end - start)
          }
          start = end++
        }
      }
      return arr
    }
    console.log(deWeight([1,1,1,2,2,3,4,5,6,3,4,2,4,1]))
  </script>
</body>
</html>